package com.example.servicea.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

import static org.springframework.http.ResponseEntity.ok;

/**
 * @author wangbin
 */
@RestController
public class TestController {
    @GetMapping("/")
    public ResponseEntity index() {
        return ok("this is service a");
    }

    @GetMapping("/test1")
    @PreAuthorize("hasAnyAuthority('USER')")
    public ResponseEntity test1() {
        Map<String, Object> map = new HashMap<>(1);
        map.put("data", "this is service a test1 method");
        return ok(map);
    }

    @GetMapping("/test2")
    @PreAuthorize("hasAnyAuthority('VIP')")
    public ResponseEntity test2() {
        Map<String, Object> map = new HashMap<>(1);
        map.put("data", "this is service a test2 method");
        return ok(map);
    }
}
